package com.zhs.smartmall.ware.service.impl;


import com.zhs.smartmall.ware.model.WmsWareInfo;
import com.zhs.smartmall.ware.dao.WmsWareInfoDao;
import com.zhs.smartmall.ware.service.IWmsWareInfoService;
import com.zhs.smartmall.ware.dto.WmsWareInfoDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author 
 * @since 2023-11-15
 */
@Service
@Slf4j
public class WmsWareInfoServiceImpl extends ServiceImpl< WmsWareInfoDao, WmsWareInfo> implements IWmsWareInfoService {

    @Resource
    private WmsWareInfoDao wmsWareInfoDao;

    @Override
    @Transactional
    public R addOrUpdate(WmsWareInfoDto wmsWareInfoDto) {
        if (BeanUtil.isEmpty(wmsWareInfoDto)) throw new ServiceException("数据不能为空");
        WmsWareInfo wmsWareInfo = new WmsWareInfo();
        BeanUtil.copyProperties(wmsWareInfoDto,wmsWareInfo);
        if (wmsWareInfoDto.getId() == null){
            wmsWareInfoDao.insert(wmsWareInfo);
            return R.ok("数据插入成功");
        }else {
            wmsWareInfoDao.updateById(wmsWareInfo);
            return R.ok("数据更新成功");
        }
    }
}